home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / Filezilla Server / FileZilla_Server-0_9_41.exe / source / interface / misc / ProcessorInfo.h < prev    next >
C/C++ Source or Header  |  2011-11-06  |  8KB  |  267 lines

  1. #ifndef PROCESSORINFO_H
  2. #define PROCESSORINFO_H
  3.  
  4. class CProcessorInfo
  5. {
  6. protected:
  7.  
  8.     SYSTEM_INFO m_sysInfo;
  9.  
  10. public:
  11.    CProcessorInfo(void)
  12.    {
  13.       ::GetSystemInfo(&m_sysInfo);
  14.    }
  15.  
  16.    virtual ~CProcessorInfo(void)
  17.    {
  18.    }
  19.  
  20.    CString GetProcessorName(void)
  21.    {
  22.       CString sRC;
  23.  
  24.       CString sSpeed;
  25.       CString sVendor;
  26.  
  27.        // Get the processor speed info.
  28.        HKEY hKey;
  29.        LONG result = ::RegOpenKeyEx (HKEY_LOCAL_MACHINE, _T("Hardware\\Description\\System\\CentralProcessor\\0"), 0, KEY_QUERY_VALUE, &hKey);
  30.  
  31.        // Check if the function has succeeded.
  32.       if (result == ERROR_SUCCESS) 
  33.       {
  34.           DWORD data;
  35.            DWORD dataSize = sizeof(data);
  36.          result = ::RegQueryValueEx (hKey, _T("~MHz"), NULL, NULL, (LPBYTE)&data, &dataSize);
  37.         
  38.          if (result == ERROR_SUCCESS)
  39.          {
  40.             sSpeed.Format ( _T("Speed: %dMHz "), data);
  41.          }
  42.          else
  43.          {
  44.             sSpeed = _T("Speed: Unknown ");
  45.          }
  46.  
  47.           TCHAR vendorData [64];
  48.            dataSize = sizeof (vendorData);
  49.  
  50.            result = ::RegQueryValueEx (hKey, _T("VendorIdentifier"), NULL, NULL, (LPBYTE)vendorData, &dataSize);
  51.  
  52.          if (result == ERROR_SUCCESS)
  53.          {
  54.             sVendor.Format ( _T("Vendor: %s "), vendorData);
  55.          }
  56.          else
  57.          {
  58.             sVendor = _T("Vendor: Unknown ");
  59.          }
  60.        }
  61.  
  62.        // Make sure to close the reg key
  63.       RegCloseKey (hKey);
  64.  
  65.       CString sType;
  66.        switch (m_sysInfo.dwProcessorType)
  67.       {
  68.       case PROCESSOR_INTEL_386:
  69.          sType = _T("Type: Intel 386 ");
  70.          break;
  71.       case PROCESSOR_INTEL_486:
  72.          sType = _T("Type: Intel 486 ");
  73.          break;
  74.       case PROCESSOR_INTEL_PENTIUM:
  75.          sType = _T("Type: Intel Pentium compatible");
  76.          break;
  77.       case PROCESSOR_MIPS_R4000:
  78.          sType = _T("Type: MIPS ");
  79.          break;
  80.       case PROCESSOR_ALPHA_21064:
  81.          sType = _T("Type: Alpha ");
  82.          break;
  83.       default:
  84.          sType = _T("Type: Unknown ");
  85.          break;
  86.        }
  87.       
  88.       CString sProcessors;
  89.       sProcessors.Format( _T("Number Of Processors: %lu "), m_sysInfo.dwNumberOfProcessors);
  90.  
  91.       CString sArchitecture;
  92.       CString sProcessorLevel;
  93.       CString sStepping;
  94.  
  95.       switch(m_sysInfo.wProcessorArchitecture)
  96.       {
  97.       case PROCESSOR_ARCHITECTURE_INTEL:
  98.          sArchitecture = _T("Architecture: Intel ");
  99.            switch (m_sysInfo.wProcessorLevel) 
  100.          {
  101.             case 3:
  102.             sProcessorLevel = _T("Level: 80386");
  103.             {
  104.                int iSteppingLevel = m_sysInfo.wProcessorRevision / 100;
  105.                int iStepping = m_sysInfo.wProcessorRevision % 100;
  106.                sStepping.Format( _T("Stepping: %c%u "), iSteppingLevel, iStepping);
  107.             }
  108.                 break;
  109.             case 4:
  110.             sProcessorLevel = _T("Level: 80486");
  111.             {
  112.                int iSteppingLevel = m_sysInfo.wProcessorRevision / 100;
  113.                int iStepping = m_sysInfo.wProcessorRevision % 100;
  114.                sStepping.Format( _T("Stepping: %c%u "), iSteppingLevel, iStepping);
  115.             }
  116.                 break;
  117.             case 5:
  118.             sProcessorLevel = _T("Level: Pentium");
  119.             {
  120.                typedef BOOL (*PIPFP)(DWORD);
  121.                    PIPFP lpfn = (PIPFP)::GetProcAddress(GetModuleHandle( _T("kernel32.dll") ), "IsProcessorFeaturePresentA");
  122.                    if (lpfn)
  123.                    {
  124.                       if ((lpfn)(PF_MMX_INSTRUCTIONS_AVAILABLE)) 
  125.                        {
  126.                           sProcessorLevel += _T (" MMX");
  127.                   }
  128.                    }
  129.  
  130.                int iModel = m_sysInfo.wProcessorRevision / 100;
  131.                int iStepping = m_sysInfo.wProcessorRevision % 100;
  132.                sStepping.Format( _T("Stepping: %u-%u "), iModel, iStepping);
  133.             }
  134.                 break;
  135.          case 6:
  136.             sProcessorLevel = _T("Level: Pentium II/Pro");
  137.             {
  138.                int iModel = m_sysInfo.wProcessorRevision / 100;
  139.                int iStepping = m_sysInfo.wProcessorRevision % 100;
  140.                sStepping.Format( _T("Stepping: %u-%u "), iModel, iStepping);
  141.             }
  142.                 break;
  143.          default:
  144.             sProcessorLevel.Format( _T("Level: Unknown %u "), m_sysInfo.wProcessorLevel);
  145.             {
  146.                int iModel = m_sysInfo.wProcessorRevision / 100;
  147.                int iStepping = m_sysInfo.wProcessorRevision % 100;
  148.                sStepping.Format( _T("Stepping: %u-%u "), iModel, iStepping);
  149.             }
  150.             break;
  151.          }
  152.          break;
  153.       case PROCESSOR_ARCHITECTURE_MIPS:
  154.          sArchitecture = "Architecture: MIPS ";
  155.          switch(m_sysInfo.wProcessorLevel)
  156.          {
  157.          case 0004:
  158.             sProcessorLevel = "Level: R4000 ";
  159.                 break;
  160.          default:
  161.             sProcessorLevel.Format( _T("Level: Unknown %u "), m_sysInfo.wProcessorLevel);
  162.             break;
  163.          }
  164.          sStepping.Format( _T("Stepping: 00%u"), m_sysInfo.wProcessorRevision);
  165.          break;
  166.       case PROCESSOR_ARCHITECTURE_ALPHA:
  167.          sArchitecture = "Architecture: Alpha ";
  168.          sProcessorLevel.Format( _T("Level: %u "), m_sysInfo.wProcessorLevel);
  169.          {
  170.             int iModel = m_sysInfo.wProcessorRevision / 100;
  171.             int iStepping = m_sysInfo.wProcessorRevision % 100;
  172.             sStepping.Format( _T("Stepping: %c%u "), iModel, iStepping);
  173.          }
  174.          break;
  175.       case PROCESSOR_ARCHITECTURE_PPC:
  176.          sArchitecture = _T("Architecture: PowerPC ");
  177.          switch(m_sysInfo.wProcessorLevel)
  178.          {
  179.             case 1:
  180.             sProcessorLevel = _T("Level: 601 ");
  181.                 break;
  182.             case 3:
  183.             sProcessorLevel = _T("Level: 603 ");
  184.                 break;
  185.             case 4:
  186.             sProcessorLevel = _T("Level: 604 ");
  187.                 break;
  188.             case 6:
  189.             sProcessorLevel = _T("Level: 603+ ");
  190.                 break;
  191.             case 9:
  192.             sProcessorLevel = _T("Level: 604+ ");
  193.                 break;
  194.             case 20:
  195.             sProcessorLevel = _T("Level: 620 ");
  196.                 break;
  197.          default:
  198.             sProcessorLevel.Format( _T("Level: Unknown %u "), m_sysInfo.wProcessorLevel);
  199.             break;
  200.          }
  201.          {
  202.             int iModel = m_sysInfo.wProcessorRevision / 100;
  203.             int iStepping = m_sysInfo.wProcessorRevision % 100;
  204.             sStepping.Format( _T("Stepping: %u.%u "), iModel, iStepping);
  205.          }
  206.          break;
  207.       case PROCESSOR_ARCHITECTURE_UNKNOWN:
  208.          sArchitecture = "Architecture: Unknown ";
  209.          sProcessorLevel.Format( _T("Level: Unknown %u "), m_sysInfo.wProcessorLevel);
  210.          {
  211.             int iModel = m_sysInfo.wProcessorRevision / 100;
  212.             int iStepping = m_sysInfo.wProcessorRevision % 100;
  213.             sStepping.Format( _T("Stepping: %u-%u "), iModel, iStepping);
  214.          }
  215.          break;
  216.       default:
  217.          sArchitecture.Format( _T("Architecture: Unknown %u "), m_sysInfo.wProcessorArchitecture);
  218.          sProcessorLevel.Format( _T("Level: Unknown %u "), m_sysInfo.wProcessorLevel);
  219.          {
  220.             int iModel = m_sysInfo.wProcessorRevision / 100;
  221.             int iStepping = m_sysInfo.wProcessorRevision % 100;
  222.             sStepping.Format( _T("Stepping: %u-%u "), iModel, iStepping);
  223.          }
  224.          break;
  225.       }
  226.  
  227.       sRC = sVendor + "," + sSpeed + "," + sType + "," + sProcessors + "," + sArchitecture + "," + sProcessorLevel + "," + sStepping;
  228.  
  229.       return sRC;
  230.    }
  231. };
  232.  
  233. class CMemoryInfo
  234. {
  235. protected:
  236.  
  237. public:
  238.  
  239.    CMemoryInfo(void)
  240.    {
  241.    }
  242.  
  243.    CString GetMemoryInfo(void)
  244.    {
  245.       CString sRC;
  246.  
  247.        MEMORYSTATUS memoryStatus;
  248.  
  249.        memset (&memoryStatus, 0, sizeof(MEMORYSTATUS));
  250.        memoryStatus.dwLength = sizeof (MEMORYSTATUS);
  251.        GlobalMemoryStatus (&memoryStatus);
  252.  
  253.       DWORD dwMinWSSize;
  254.       DWORD dwMaxWSSize;
  255.  
  256.       ::GetProcessWorkingSetSize(GetCurrentProcess(), &dwMinWSSize, &dwMaxWSSize);
  257.  
  258.       sRC.Format( _T("Memory Used %lu%%, Total Physical Memory %luKB, Physical Memory Available %luKB, Total Virtual Memory %luKB, Available Virtual Memory %luKB, Working Set Min : %luKB Max : %luKB .\r\n"), memoryStatus.dwMemoryLoad, memoryStatus.dwTotalPhys / 1024, memoryStatus.dwAvailPhys / 1024, memoryStatus.dwTotalVirtual / 1024, memoryStatus.dwAvailVirtual / 1024, dwMinWSSize/1024, dwMaxWSSize/1024);
  259.  
  260.       return sRC;
  261.    }
  262.  
  263. };
  264.  
  265. #endif
  266.  
  267.